import 'package:date_format/date_format.dart';
import 'package:honeypotflutter/public/public_chineseDateLocale.dart';

class MGBussineDate {
  /*
  * 获取月份第一天和最后一天
  * */
  static BussineSelectDateModel calculateDate({int? yy, int? mm}) {
    int year = yy ?? DateTime.now().year;
    int month = mm ?? DateTime.now().month;
    DateTime monthStart = DateTime(year, month, 1);
    DateTime monthEnd = DateTime.now(); // 获取本月第一天的日期时间
    if (month != DateTime.now().month) {
      monthEnd = DateTime(year, month + 1, 0); // 获取本月最后一天的日期时间
    }
    return BussineSelectDateModel(
      formatDate(monthStart, [yyyy, '-', MM, '-', dd], locale: const ChineseDateLocale()),
      formatDate(monthEnd, [yyyy, '-', MM, '-', dd], locale: const ChineseDateLocale()),
      "${year}年${month}月",
    );
  }

  /*
  * 获取结束时间及前后几个月时间
  * */
  static BussineSelectDateModel calculateMonthDate(int month) {
    DateTime endTime = DateTime.now();
    DateTime startTime = DateTime(endTime.year, endTime.month + month, endTime.day);
    return BussineSelectDateModel(
      formatDate(startTime, [yyyy, '-', mm, '-', dd]),
      formatDate(endTime, [yyyy, '-', mm, '-', dd]),
      "",
    );
  }
}

class BussineSelectDateModel {
  String startTime;
  String endTime;
  String currentTime;
  BussineSelectDateModel(this.startTime, this.endTime, this.currentTime);
}
